public class Complex{
private double Realpart;
private double Imagepart;
    public Complex(double Realpart,double Imagepart)
    {
this.Realpart=Realpart;
this.Imagepart=Imagepart;
}

    public double getImagepart() {
        return Imagepart;
    }

    public void setImagepart(double imagepart) {
        Imagepart = imagepart;
    }

    public double getRealpart() {
        return Realpart;
    }

    public void setRealpart(double realpart) {
        Realpart = realpart;
    }
    public String toString()
    {
        if(this.getImagepart()>0)
        return this.getRealpart()+"+"+this.getImagepart()+"i";
        if(this.getRealpart()==0)
            return this.getImagepart()+"i";
        else
            return this.getRealpart()+this.getImagepart()+"i";
    }
    public Complex addComplex(Complex a)
    {


        return new Complex(this.getRealpart()+a.getRealpart(),this.getImagepart()+a.getImagepart());
    }

    public Complex subComplex(Complex a)
    {
        return new Complex(this.getRealpart()-a.getRealpart(),this.getImagepart()-a.getImagepart());
    }
    public Complex mulComplex(Complex a)
    {
        return new Complex(this.getRealpart()*a.getRealpart()-this.getImagepart()*a.getImagepart(),this.getImagepart()*a.getRealpart()+this.getRealpart()*a.getImagepart());
    }
    public Complex divComplex(Complex a)
    {
        return new Complex((this.getRealpart()*a.getRealpart()+this.getImagepart()*a.getImagepart())/(Math.pow(a.getRealpart(),2)+Math.pow(a.getImagepart(),2)),(this.getImagepart()*a.getRealpart()-this.getRealpart()*a.getImagepart())/(Math.pow(a.getRealpart(),2)+Math.pow(a.getImagepart(),2)));
    }
}